#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "setsizedlg.h"

//#include <QDebug>
#include <QPen>
#include <QBrush>


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    myView = new GraphicsView;
    myScene = new GraphicsScene;

    myView->setScene(myScene);//初始化场景及视口
    myView->setRenderHint(QPainter::Antialiasing);
    myView->setBackgroundBrush(QPixmap(":/image/background.jpg"));
    myView->setCacheMode(QGraphicsView::CacheBackground);
    ui->gridLayout->addWidget(myView);

    canvas = new QGraphicsRectItem;//初始化画布
    canvas->setPen(QPen(Qt::white));
    canvas->setBrush(QBrush(Qt::white));
    myScene->addItem(canvas);
    //myScene->setSceneRect();
    canvas->setZValue(0);

    rubber = new QGraphicsRectItem;//初始化橡皮选框
    rubber->setPen(QPen(Qt::black));
    myScene->addItem(rubber);
    rubber->setZValue(0);

    this->setSize(400, 400);


}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_actionSetSize_triggered()
{
    setSizeDlg *dlg;
    dlg = new setSizeDlg;
    connect(dlg, SIGNAL(setSize(int, int)),
            this, SLOT(setSize(int, int)));
    dlg->show();
}

void MainWindow::setSize(int length, int width)
{
    canvas->setRect(0 ,0 , length, width);
}

void MainWindow::initSelectRubber()
{
    rubber->setRect(0, 0, 0, 0);
}

void MainWindow::recvStartPoint(int x1, int y1)
{

}

void MainWindow::recvEndPoint(int x2, int y2)
{

}
